<template>
    <div id="invest-summary-result">
        <!-- 表格工具栏 -->
        <div class="header-search">
            <el-row :gutter="10">
                <el-form label-width="90px">
                    <el-col :span="6">
                        <el-form-item label="证券代码">
                            <el-select
                                v-model="searchParams.stockCode"
                                filterable
                                clearable
                                @clear="getBondCodeList('')"
                                remote
                                :remote-method="getBondCodeList"
                                :loading="selectLoading"
                                placeholder="请输入代码或名称"
                                size="mini"
                                style="width: 100%"
                            >
                                <el-option
                                    v-for="item in bondCodeSelectData"
                                    :key="item.dictKey"
                                    :label="item.dictKey + ' ' + item.dictKeyName"
                                    :value="item.dictKey"
                                >
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item label="产品代码" :class="{ isInput: searchParams.fundCodes.length > 0 }">
                            <el-select
                                v-model="searchParams.fundCodes"
                                style="width: 100%"
                                size="mini"
                                multiple
                                collapse-tags
                                filterable
                                @change="handleParam('fundCodes')"
                            >
                                <el-option
                                    v-for="item in funds"
                                    :key="item.fundCode"
                                    :value="item.fundCode"
                                    :label="item.showCode + ' ' + item.fundNameSt"
                                ></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>

                    <el-col :span="6" v-show="show">
                        <el-form-item label="下达人">
                            <el-select v-model="searchParams.direactUser" clearable filterable style="width: 100%" size="mini">
                                <el-option
                                    v-for="item in orderUsers"
                                    :key="item.dictKey"
                                    :value="item.dictCode"
                                    :label="item.dictKey + ' ' + item.dictKeyName"
                                ></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6" v-show="show">
                        <el-form-item label="指令类型">
                            <el-select v-model="searchParams.requestType" clearable filterable style="width: 100%" size="mini">
                                <el-option
                                    v-for="item in requestType"
                                    :key="item.dictKey"
                                    :value="item.dictKey"
                                    :label="item.dictKeyName"
                                ></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6" v-show="show">
                        <el-form-item label="指令状态">
                            <el-select v-model="searchParams.instructionStatus" clearable filterable style="width: 100%" size="mini">
                                <el-option
                                    v-for="item in instructionStatus"
                                    :key="item.dictKey"
                                    :value="item.dictKey"
                                    :label="item.dictKeyName"
                                ></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6" v-show="show">
                        <el-form-item label="证券类别">
                            <el-select v-model="searchParams.stockType" clearable filterable style="width: 100%" size="mini">
                                <el-option v-for="item in stockType" :key="item.dictKey" :value="item.dictKey" :label="item.dictKeyName"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6" v-show="show">
                        <el-form-item label="委托方向">
                            <el-select v-model="searchParams.orderDirection" clearable filterable style="width: 100%" size="mini">
                                <el-option
                                    v-for="item in orderDirection"
                                    :key="item.dictKey"
                                    :value="item.dictKey"
                                    :label="item.dictKeyName"
                                ></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6" v-show="show">
                        <el-form-item label="风险结果">
                            <el-select v-model="searchParams.riskResult" multiple collapse-tags style="width: 100%" size="mini">
                                <el-option
                                    v-for="item in thresholdType"
                                    :key="item.dictKey"
                                    :value="item.dictKey"
                                    :label="item.dictKeyName"
                                ></el-option>
                            </el-select>
                        </el-form-item>
                        <!-- formatter={value => `${value || ''}`.replace(/\B(?=(\d{3})+(?!\d))/g, ',')} -->
                    </el-col>
                    <el-col :span="6" v-show="show">
                        <el-form-item label="指令序号">
                            <el-input-number
                                style="width: 100%"
                                size="mini"
                                v-model="searchParams.instructionNo"
                                controls-position="right"
                                :min="0"
                                :precision="0"
                            ></el-input-number>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6" v-show="show">
                        <el-form-item label="恒生指令序号">
                            <el-input style="width: 100%" size="mini" v-model="searchParams.hsinstructionNo" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="6" v-show="show">
                        <el-form-item label="外部指令序号">
                            <el-input style="width: 100%" size="mini" v-model="searchParams.outOrderCode" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="6" v-show="show">
                        <el-form-item label="数据来源类型">
                            <RiskCustomSelect
                                :selectKeys="searchParams.dataSourceType"
                                :dataSource="nameType.dataSourceType"
                                :showSearch="false"
                                :key="dataSourceTypeNumKey + 'dataSourceTypeNumKey'"
                                @customSelectReturn="customSelectReturn"
                                style="width: 100%"
                            ></RiskCustomSelect>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6" v-show="type === 'history' && show">
                        <el-form-item label="下达日期">
                            <!-- <el-date-picker
                                v-model="searchParams.directDates"
                                type="daterange"
                                value-format="yyyyMMdd"
                                format="yyyy-MM-dd"
                                range-separator="至"
                                size="mini"
                                style="width: 100%"
                                @change="handleDateChange"
                            >
                            </el-date-picker> -->

                            <el-date-picker
                                v-model="searchParams.directDateStart"
                                placeholder="开始日期"
                                :picker-options="DatePickerS"
                                value-format="yyyyMMdd"
                                format="yyyy-MM-dd"
                                size="mini"
                                style="width: calc(50% - 4px)"
                            >
                            </el-date-picker>
                            <span>-</span>
                            <el-date-picker
                                name="结束日期"
                                v-model="searchParams.tradeDateEnd"
                                placeholder="结束日期"
                                :picker-options="DatePickerE"
                                value-format="yyyyMMdd"
                                format="yyyy-MM-dd"
                                size="mini"
                                style="width: calc(50% - 4px)"
                            >
                            </el-date-picker>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6" v-show="SHOW_SECURITY && show">
                        <el-form-item label="组合编码" :class="{ isInput: searchParams.fundCodes.length > 0 }">
                            <el-select v-model="searchParams.fundAccountCodes" style="width: 100%" size="mini" multiple collapse-tags filterable>
                                <el-option
                                    v-for="i in fundAccountCodeSelectData"
                                    :key="i.fundAccountCode"
                                    :label="i.fundAccountCode + ' ' + i.fundAccountName"
                                    :value="i.fundAccountCode"
                                >
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-form>
            </el-row>
            <el-row style="text-align: right">
                <el-button type="primary" @click="handleButtonClick('reset')">重置</el-button>
                <el-button type="primary" v-authCode="B_0125" @click="handleButtonClick('search')">查询</el-button>
                <el-button type="primary" @click="handleButtonClick('export')">导出</el-button>
                <el-button @click="handleShowOrHide" style="margin-right: 30px">{{ show ? '隐藏' : '展开' }}</el-button>
                <el-button type="primary" @click="handleButtonClick('layout')">布局设置</el-button>
                <!-- isVerifyAuth={false} -->
            </el-row>
        </div>

        <RiskTable
            ref="risk-table"
            :tableData="tableData"
            :tableConfig="tableConfig"
            :column="showColumns"
            :paging="paging"
            :searchParams="searchParams"
            v-loading="tableLoading"
            :key="tableKey"
            :style="{ height: show ? 'calc(100% - 225px)' : 'calc(100% - 105px)' }"
            @page-change="getTableData"
        >
            <template #riskResult="{ row }">
                <StatusTag :code="row.riskResult"></StatusTag>
            </template>
            <template #realDirection="{ row }">
                {{ orderDirectionEnum[row.realDirection] }}
            </template>
            <template #dataSourceType="{ row }">
                {{ DataSourceTypesEnum[row.dataSourceType] }}
            </template>
            <template #thresholdType="{ row }">
                <StatusTag :code="row.thresholdType"></StatusTag>
            </template>

            <template #operation="{ row }">
                <RiskIconButton
                    type="primary"
                    :disabled="!row.resultId"
                    icon="el-icon-view"
                    topTitle="查看"
                    size="mini"
                    @on-click="handleBtnLook(row)"
                ></RiskIconButton>
            </template>
        </RiskTable>

        <!-- 布局设置 -->
        <RiskTableLayout
            ref="risk-table-layout"
            :tableName="type === 'history' ? 'TH_INSTRUCTION_RESULT' : 'TI_INSTRUCTION_RESULT'"
            :visible.sync="layoutDialog"
            :column="columns"
            :fixedColumns="fixedColumns"
            :resetNoSelectedFieldList="resetNoSelectedFieldList"
        />
    </div>
</template>
<script lang="ts">
import { ColumnVO, PageVO, TableConfigVO, VueObject } from '@/common/vo';
import { dateFormat, getConfigItem, numberFormat, timeFormat, unitShow, numberFormatCIB } from '@/utils/tools';
import { Component, Vue, Prop } from 'vue-property-decorator';
// import Dict from '../dict/index';
import RiskTable from '@/common/components/risk-table-plus.vue';
import RiskTableLayout from '@/common/components/risk-table-layout-plus.vue';
import DictionConstUtil, { SGU_CACHE } from '@/utils/diction-const-util';
import RiskCustomSelect from '@/common/components/risk-custom-select.vue';
import Invest from '@/common/dict/invest';
import RiskIconButton from '@/common/components/risk-icon-button.vue';
import StatusTag from '@/pages/risk-measure/components/status-tag.vue';
import { downLoadFile } from '@/utils/request';
import moment from 'moment';
import XEUtils from 'xe-utils';

@Component({ name: 'InvestSummaryResult', components: { RiskTable, RiskTableLayout, RiskCustomSelect, RiskIconButton, StatusTag } })
export default class InvestSummaryResult extends Vue {
    @Prop() type: string;

    invest = new Invest();
    // Dict = new Dict();

    SHOW_SECURITY = getConfigItem('SHOW_SECURITY');

    tableLoading: boolean = false;
    tableData: any[] = [];
    tableConfig: TableConfigVO = {
        rowKey: 'instNoId', // 主键key
        allRowKeys: [], // 所有页数据的key集合
    };
    columns: ColumnVO[] = [
        {
            type: 'checkbox', // 复选框
            // selectedAll: true, // 选中所有页
            fixed: 'left',
            align: 'center',
            width: 60,
        },
        {
            title: '指令序号',
            field: 'instructionNo',
            sortable: true,
            sortField: 'N_INST_NO',
            fixed: 'left',
            minWidth: 100,
        },
        {
            title: '恒生指令序号',
            field: 'dailyInstructionNo',
            sortable: true,
            sortField: 'N_DAILY_INSTRUCTION_NO',
            minWidth: 140,
        },
        {
            title: '指令批号',
            field: 'batchNo',
            sortable: true,
            sortField: 'N_BATCH_NO',
            minWidth: 120,
        },
        {
            title: '证券代码',
            field: 'stockCode',
            sortable: true,
            sortField: 'C_STOCK_CODE',
            minWidth: 100,
        },
        {
            title: '证券名称',
            field: 'stockNameSt',
            sortable: true,
            sortField: 'C_STOCK_NAME_ST',
            minWidth: 130,
        },
        {
            title: '业务类型',
            field: 'businessTypeName',
            sortable: true,
            sortField: 'C_BUSINESS_TYPE_NAME',
            minWidth: 140,
        },
        {
            title: '委托方向',
            field: 'realDirection',
            sortable: true,
            sortField: 'C_REAL_DIRECTION',
            minWidth: 100,
            // render: value => this.orderDirectionEnum[value],
        },
        {
            title: '风险结果',
            field: 'riskResult',
            sortable: true,
            sortField: 'C_THRESHOLD_TYPE',
            minWidth: 100,
        },
        {
            title: '产品代码',
            field: 'fundCode',
            sortable: true,
            sortField: 'C_FUND_CODE',
            minWidth: 100,
        },
        {
            title: '产品名称',
            field: 'fundName',
            sortable: true,
            sortField: 'C_FUND_NAME',
            minWidth: 120,
        },
        {
            title: '资产单元编号',
            field: 'assetCode',
            sortable: true,
            sortField: "TO_NUMBER(REGEXP_REPLACE(C_ASSET_CODE,'[^0-9]',''))",
            minWidth: 130,
        },
        {
            title: '资产单元名称',
            field: 'assetName',
            sortable: true,
            sortField: 'C_ASSET_NAME',
            minWidth: 130,
        },
        {
            title: '组合编码',
            field: 'fundAccountCode',
            sortable: true,
            sortField: "TO_NUMBER(REGEXP_REPLACE(C_FD_AC_CODE,'[^0-9]',''))",
            minWidth: 100,
        },
        {
            title: '组合名称',
            field: 'fdAcName',
            sortable: true,
            sortField: 'C_FD_AC_NAME',
            minWidth: 120,
        },
        {
            title: '交易市场',
            field: 'marketName',
            sortable: true,
            sortField: 'C_MARKET_NAME',
            minWidth: 100,
        },
        {
            title: '转入组合编码',
            field: 'destCombiId',
            sortable: true,
            sortField: 'DEST_COMBI_ID',
            minWidth: 140,
        },
        {
            title: '转入组合名称',
            field: 'destCombiName',
            sortable: true,
            sortField: 'DEST_COMBI_NAME',
            minWidth: 140,
        },
        {
            title: '转入证券代码',
            field: 'destSecurityCode',
            sortable: true,
            sortField: 'DEST_SECURITY_CODE',
            minWidth: 140,
        },
        {
            title: '转入证券名称',
            field: 'destSecurityName',
            sortable: true,
            sortField: 'DEST_SECURITY_NAME',
            minWidth: 140,
        },
        {
            title: '转入投资类型',
            field: 'investTypeName',
            sortable: true,
            sortField: 'C_INVEST_TYPE_NAME',
            minWidth: 140,
            render: (value, record) => (record.realDirection === 'E' ? value : '--'),
        },
        {
            title: '巨额赎回',
            field: 'bulkType',
            sortable: true,
            sortField: 'BULK_TYPE',
            minWidth: 100,
            render: value => this.invest.bulkType[value] || '--',
        },
        {
            title: '指令状态',
            field: 'instrctionStatus',
            sortable: true,
            sortField: 'C_INST_STATUS',
            minWidth: 100,
            render: value => this.invest.instructionStatus[value],
        },
        {
            title: '指令类型',
            field: 'requestType',
            sortable: true,
            sortField: 'C_REQUEST_TYPE',
            minWidth: 120,
            render: value => this.invest.requestType[value],
        },
        {
            title: '来源类型',
            field: 'sourceType',
            sortable: true,
            sortField: 'C_SOURCE_TYPE',
            minWidth: 100,
            render: value => DictionConstUtil.SourceType[value],
        },
        {
            title: '数据来源类型',
            field: 'dataSourceType',
            sortable: true,
            sortField: 'C_SOURCE_TYPE',
            minWidth: 130,
            // render: value => this.DataSourceTypesEnum[value],
        },
        {
            title: '下达日期',
            field: 'directDate',
            sortable: true,
            sortField: 'CONCAT(D_DIRECT_DATE,D_DIRECT_TIME)',
            minWidth: 170,
            render: (value, record) => dateFormat(value) + ' ' + timeFormat(record.directTime),
        },
        {
            title: '下达人',
            field: 'direactUser',
            sortable: true,
            sortField: 'C_DIREACT_USER',
            minWidth: 100,
            render: (value, record) => (record.hsOrderUserName && record.hsOrderUserName.trim()) || (record.direactUser && record.direactUser.trim()),
        },
        // {
        //     title: '原始证券代码',
        //     field: 'stockCode',
        //     minWidth: 150,
        //     sortable: true,
        //     filters: [{ data: '' }],
        // },
        {
            title: '指令落库日期',
            field: 'createDate',
            sortable: true,
            sortField: 'CONCAT(D_DT_CT_DATE_YH,D_DT_CT_TIME_YH)',
            minWidth: 170,
            render: (value, record) => dateFormat(value) + ' ' + timeFormat(record.directTime),
        },
        {
            title: '条目编号',
            field: 'entryCode',
            sortable: true,
            sortField: 'C_ENTRY_CODE',
            minWidth: 100,
        },
        {
            title: '风险说明',
            field: 'entryName',
            sortable: true,
            sortField: 'C_ENTRY_NAME',
            minWidth: 300,
        },
        // {
        //     title: '触警类型',
        //     field: 'thresholdType',
        //     sortable: true,
        //     sortField: 'C_THRESHOLD_TYPE',
        //     minWidth: 100,
        // },
        {
            title: '条目触发值',
            field: 'thresholdValue',
            sortable: true,
            sortField: 'N_THRESHOLD_VALUE',
            minWidth: 120,
            render: (value, record) => (value != undefined ? numberFormatCIB(value, record.unit, 'thresholdValue') + unitShow(record.unit) : '--'),
        },
        {
            title: '条目比较方向',
            field: 'compareType',
            sortable: true,
            sortField: 'C_COMPARE_TYPE',
            minWidth: 130,
            render: value => DictionConstUtil.CompareDirection[value],
        },
        {
            title: '计算结果(单位)',
            field: 'calculateValue',
            sortable: true,
            sortField: 'N_RESULT',
            minWidth: 170,
            render: (value, record) => (value != undefined ? numberFormatCIB(value, record.unit) + unitShow(record.unit) : '--'),
        },
        {
            title: '计算逻辑',
            field: 'calLogicShow',
            sortable: true,
            sortField: 'C_CAL_LOGIC_SHOW',
            minWidth: 200,
        },
        {
            title: '是否报错',
            field: 'errorValid',
            minWidth: 100,
            type: 'func',
            render: value => (value === '0' ? '否' : '是'),
        },
        {
            title: '报错信息',
            field: 'errorMessage',
            minWidth: 120,
        },
        {
            title: '条目KEY',
            field: 'entryKey',
            minWidth: 150,
        },
        {
            title: '流水号',
            field: 'resultId',
            sortable: true,
            sortField: 'N_RESULT_ID',
            minWidth: 150,
        },
        {
            title: '计算日期',
            field: 'calculateDate',
            sortable: true,
            sortField: 'D_CAL_DATE',
            minWidth: 150,
            render: (value, record) => dateFormat(value) + ' ' + timeFormat(record.calculateTime) || '--',
        },
        {
            title: '操作',
            field: 'operation',
            fixed: 'right',
            width: 100,
            align: 'center',
        },
    ];
    showColumns: ColumnVO[] = [];
    fixedColumns: ColumnVO[] = [
        { title: '指令序号', field: 'instructionNo' },
        { title: '恒生指令序号', field: 'dailyInstructionNo' },
        { title: '指令批号', field: 'batchNo' },
        { title: '证券代码', field: 'stockCode' },
        // { title: '产品代码', field: 'fundCode' },  // 只能固定在前方或者后方 不能根据预设的位置插入
        // { title: '条目编号', field: 'entryCode' },
        { title: '操作', field: 'operation' },
    ];
    resetNoSelectedFieldList: ColumnVO[] = [];
    tableKey: number = 0;
    searchParams: any = {
        direactUser: '',
        fundCodes: [],
        fundAccountCodes: [], // 券商模式
        requestType: '',
        instructionStatus: '',
        stockCode: '',
        stockType: '',
        orderDirection: '',
        instructionNo: undefined,
        outOrderCode: '',
        directDate: '',
        directDateStart: XEUtils.toDateString(new Date(new Date().getTime() - 24 * 60 * 60 * 1000), 'yyyyMMdd'),
        tradeDateEnd: XEUtils.toDateString(new Date(), 'yyyyMMdd'),
        riskResult: '', // 风险结果
        hsinstructionNo: '',
        dataSourceType: ['1', '2', '3'],
        showError: true, // 显示错误类型
    };
    paging: PageVO = { pageSize: 25, currentPage: 1, total: 0 };

    layoutDialog: boolean = false;
    exportVisible: boolean = false;

    checkRowKeys: string[] = [];
    checkedRows: any[] = [];

    selectLoading: boolean = false; // 下拉框加载
    bondCodeSelectData: any[] = []; // 证券代码下拉框数据
    fundAccountCodeSelectData: any[] = []; // 组合编码下拉框数据
    funds: any[] = []; // 产品代码
    show: boolean = false; // 展示或者隐藏
    orderUsers: any[] = []; // 下达人下拉列表
    requestType: any[] = []; // 指令类型
    instructionStatus: any[] = []; // 指令状态
    stockType: any[] = []; // 证券类别
    orderDirection: any[] = []; // 订单方向
    thresholdType: any[] = []; // 触警类型/风险结果
    nameType: any = {
        dataSourceType: [],
        marketCode: {}, // 交易市场
    };
    dataSourceTypeNumKey: number = -1; // 下拉数据类型Key
    DataSourceTypesEnum: any = {};
    orderDirectionEnum: any = {};

    async mounted() {
        // 监听布局设置
        this.$watch(
            () => {
                return (this.$refs['risk-table-layout'] as VueObject).showColumns;
            },
            val => {
                this.showColumns = val && val.length ? val : this.columns;
                this.tableKey++;
            }
        );

        if (this.SHOW_SECURITY) {
            this.$axios.get('/fdAc/list/byFundCode').then((res: any) => {
                this.fundAccountCodeSelectData = res;
            });
        }
        this.funds = await SGU_CACHE('FundInfoByUser', '/fundInfo/list/byUser/like', []);

        // 下达人下拉列表
        this.$axios.post('/instruction/user/select').then((res: any) => {
            this.orderUsers = res;
        });
        // 指令类型
        this.requestType = DictionConstUtil.PojoToList(this.invest.requestType);
        // 指令状态
        this.instructionStatus = DictionConstUtil.PojoToList(this.invest.instructionStatus);
        // 证券类别
        this.stockType = await DictionConstUtil.FNStockType();
        // 指令类型
        this.requestType = DictionConstUtil.PojoToList(this.invest.requestType);
        // 订单方向
        this.orderDirection = await DictionConstUtil.FNTradeDirection();
        this.orderDirectionEnum = DictionConstUtil.ListToPojo(this.orderDirection);
        // 触警类型/风险结果
        this.thresholdType = DictionConstUtil.PojoToList(DictionConstUtil.ThresholdType);
        let values = await DictionConstUtil.FNInstructionDataSourceType();
        this.DataSourceTypesEnum = DictionConstUtil.ListToPojo(values);
        let dataSourceTypes = JSON.parse(JSON.stringify(values)).sort((a, b) => {
            return a.dictKey > b.dictKey ? 1 : -1;
        });
        this.dataSourceTypeNumKey++;
        this.nameType.dataSourceType = dataSourceTypes;
        this.getTableData();
    }

    getTableData() {
        this.tableLoading = true;
        let url = '/instruction/result/list';
        if (this.type === 'history') {
            url = '/instruction/history/result/list';
        }
        this.$axios({ method: 'POST', url, data: { ...this.searchParams, paging: this.paging } })
            .then((res: any) => {
                this.tableData = res?.list || [];
                this.paging.total = res?.total || 0;
            })
            .finally(() => {
                this.tableLoading = false;
            });
    }

    /**
     * 获取证券代码下拉框数据
     */
    getBondCodeList(e: string): void {
        this.selectLoading = true;
        this.$axios
            .post('/dict/comprehensive/stock/select', {
                dictKey: e,
                dictKeyName: e,
            })
            .then((res: any) => {
                // console.log(res);

                this.bondCodeSelectData = res || [];
                this.selectLoading = false;
            })
            .catch(() => {
                this.selectLoading = false;
            });
    }

    handleParam(param: string) {
        if (param == 'fundCodes') {
            // 获取组合编码下拉框数据
            this.$nextTick(() => {
                this.searchParams.fundAccountCodes = this.searchParams.fundAccountCodes.filter(key => {
                    let index = this.fundAccountCodeSelectData.findIndex(item => item.fundAccountCode == key);
                    return index > -1;
                });
            });
        }
    }

    // 是否展开
    handleShowOrHide(): void {
        this.show = !this.show;
    }

    // 下拉多选框回调
    customSelectReturn(values: any): void {
        this.searchParams.dataSourceType = values;
    }

    submitExport(): void {
        // API.downLoadFileContract(this.exportParams);
        this.exportVisible = false;
    }

    // 按钮点击
    handleButtonClick(action: string) {
        if (action === 'search') {
            this.getTableData();
        } else if (action === 'layout') {
            this.layoutDialog = true;
        } else if (action == 'reset') {
            this.reset();
            this.getBondCodeList('');
            this.dataSourceTypeNumKey++;
        } else if (action == 'export') {
            this.checkRowKeys = (this.$refs['risk-table'] as any).checkRowKeys;

            let url = '/instruction/result/export';
            if (this.type === 'history') {
                url = '/instruction/history/result/export';
            }
            downLoadFile({
                url,
                method: 'post',
                data: {
                    exportKeys: this.checkRowKeys,
                    ...this.searchParams,
                    columns: this.showColumns,
                },
                loadingMsg: '正在准备导出 请稍后... ... ',
            });
        }
    }

    // 查看按钮点击
    private handleBtnLook(obj: any): void {
        // 点击的指令结果行、是否为历史数据、当前行(指令)
        this.$emit('handelOperate', { record: obj, history: this.type === 'history', clickRecord: {} });
    }

    reset() {
        this.searchParams = {
            direactUser: '',
            fundCodes: [],
            fundAccountCodes: [], // 券商模式
            requestType: '',
            instructionStatus: '',
            stockCode: '',
            stockType: '',
            orderDirection: '',
            instructionNo: undefined,
            outOrderCode: '',
            directDate: '',
            directDateStart: XEUtils.toDateString(new Date(new Date().getTime() - 24 * 60 * 60 * 1000), 'yyyyMMdd'),
            tradeDateEnd: XEUtils.toDateString(new Date(), 'yyyyMMdd'),
            riskResult: '', // 风险结果
            hsinstructionNo: '',
            dataSourceType: ['1', '2', '3'],
            showError: true, // 显示错误类型
        };
    }

    /**
     * 下达日期 变动事件
     */
    handleDateChange(vals: string[]): void {
        if (vals && vals.length) {
            this.searchParams.directDateStart = vals[0];
            this.searchParams.tradeDateEnd = vals[1];
        } else {
            this.searchParams.directDateStart = '';
            this.searchParams.tradeDateEnd = '';
        }
    }

    DatePickerS = {
        disabledDate: time => {
            // 开始日期不能比今天大
            let maxDate = new Date().getTime();
            return time.getTime() > maxDate;
        },
    };

    DatePickerE = {
        disabledDate: time => {
            let minDate;
            let maxDate;
            if (this.searchParams.directDateStart) {
                const directDateStart = moment(this.searchParams.directDateStart).format('yyyy-MM-DD');
                // 结束日期不能比开始日期小
                minDate = Date.parse(directDateStart);
                // 结束日期不能比今天大
                let maxDate = new Date().getTime();
                return time.getTime() > maxDate || time.getTime() <= minDate - 3600 * 1000 * 24;
            }
            // 结束日期不能比今天大
            maxDate = new Date().getTime();
            return time.getTime() > maxDate || time.getTime() <= minDate - 3600 * 1000 * 24;
        },
    };
}
</script>
<style lang="scss" scoped>
#invest-summary-result {
    height: 100%;
    padding: 10px 20px;

    .header-search {
        border: 1px solid #ccc;
        padding: 10px;
        margin-bottom: 10px;
        /deep/.el-form-item {
            margin-bottom: 0px;
            .el-form-item__label {
                padding: 0;
                color: black;
            }
        }
        .isInput /deep/ .el-select__input {
            margin-left: 2px;
        }
    }
}

/deep/ .el-input__inner {
    height: 28px;
    line-height: 28px;
}
</style>
